﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.BLL;

namespace Domain.DAL
{
    class ProductDAL
    {

        public List<ProductBLL> listOfAllProducts()
        {            
            using (var ctx = new CSEntities())
            {
                var _pl = (from _p in ctx.Products
                           select new ProductBLL
                           {
                               ProductID = _p.ProductID,
                               ProductName = _p.ProductName,
                               CategoryID = _p.CategoryID,                               
                               SupplierID = _p.SupplierID,
                               PriceIn = _p.PriceIn,
                               SalePrice = _p.SalePrice,
                               WarrantyTime = _p.WarrantyTime,
                               QuantityInStock = _p.QuantityInStock,
                               ImageName = _p.ImageName,
                               Description = _p.Description,
                               isAvailable = _p.isAvailable,
                           });

                return _pl.ToList();
            }

            //return lp;
        }

        public List<ProductBLL> ListProductByCategory(int CatId)
        {
            using (var ctx = new CSEntities())
            {
                var _pl = (from _p in ctx.Products
                           where _p.CategoryID == CatId
                           select new ProductBLL
                           {
                               ProductID = _p.ProductID,
                               ProductName = _p.ProductName,
                               CategoryID = _p.CategoryID,
                               SupplierID = _p.SupplierID,
                               PriceIn = _p.PriceIn,
                               SalePrice = _p.SalePrice,
                               WarrantyTime = _p.WarrantyTime,
                               QuantityInStock = _p.QuantityInStock,
                               ImageName = _p.ImageName,
                               Description = _p.Description,
                               isAvailable = _p.isAvailable,
                           });

                return _pl.ToList();
            }
        }
    }
}
